document.write('<script type="text/javascript" src="../../js/tableScoll.js"></script>');
//ajax 通用方法
$(document).ready(function () {
	$(document).keydown(function(event) { 
		if (event.keyCode == 13) { 
			var counter = $("#adminCounter").val();
			var password = $("#adminPassWord").val();
		    if(counter =="" ||  password == "" || counter ==null ||  password == null){
		    	alert("密码或账户不能为空");
		    	return;
		    }
		    var params = "adminCounter="+counter +"&adminPassWord=" + password;
	        $.ajax({  
	            url:'/STUMS/loginCheck.action',  
	            type:'post',  
	            data:params,  
	            dataType:'json',  
	            success:function (data) { 
	    		 if(data.result == "success" ){
	    			 $("#counter").attr("value",counter);
	    			 $("#loginForm").submit();
	    		 }else{
	    			 alert("密码或账号出错");
	    		 }
	            },
	            error:function(xhr){alert(xhr.responseText);}  
	        });  
		}
	}); 
	
	$("#login").click(function() {
		var counter = $("#adminCounter").val();
		var password = $("#adminPassWord").val();
	    if(counter =="" ||  password == "" || counter ==null ||  password == null){
	    	alert("密码或账户不能为空");
	    	return;
	    }
	    var params = "adminCounter="+counter +"&adminPassWord=" + password;
        $.ajax({  
            url:'/STUMS/loginCheck.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) { 
    		 if(data.result == "success" ){
    			 $("#counter").attr("value",counter);
    			 $("#loginForm").submit();
    		 }else{
    			 alert("密码或账号出错");
    		 }
            },
            error:function(xhr){alert(xhr.responseText);}  
        });  
    });

	//菜单
	$("#menuModify").click(function(){
		var value="";
		$("input[type='checkbox'][ id='_ckId']").each(function(){ 
			if ($(this).attr("checked")) { 
				value += $(this).val() + ",";
			} 
		})  
		if(value.split(",").length > 2){
			alert("只能选择一个菜单进行修改！");
			return;
		}
		if(value == ""){
			alert("请选择一个菜单进行修改！");
			return;
		}
		var params = "id=" + value.substring(0,value.length-1);
		window.location.href="./menuAction_modifyMenuSearch.action?id=" + value.substring(0,value.length-1);
	});
	
	
	//用户修改页面对用户信息查询
	$("#adminModify").click(function(){
		var value="";
		$("input[type='checkbox'][ id='_ckId']").each(function(){ 
			if ($(this).attr("checked")) { 
				value += $(this).val() + ",";
			} 
		})  
		if(value.split(",").length > 2){
			alert("只能选择一个用户进行修改！");
			return;
		}
		if(value == ""){
			alert("请选择一个用户进行修改！");
			return;
		}
		var params = "id=" + value.substring(0,value.length-1);
		window.location.href="./adminAction_modifyAdminSearch.action?id=" + value.substring(0,value.length-1);
	});
	
	
	$("#saveAuthorMenu").click(function(){
		 var activeMenu = "";
		 var noActMenu = "";
		 var adminNumber = $("#adminNumber").val();
		 if(adminNumber == null || adminNumber == ""){
			 alert("请输入您要搜索的账号！");
			 return;
		 }
		 $("select").each(function(){
		    var selectId = $(this).attr("id");
   			if($(this).val()  == "1000"){
   				activeMenu  = activeMenu + selectId+ ",";
   			}
   			if($(this).val()  =="9999"){
   				noActMenu  = noActMenu + selectId+ ",";
   			}
   		 });
		 
	    if( (activeMenu == "" || activeMenu ==null) && (noActMenu =="" || noActMenu ==null)){
	    	 alert("请先搜索用户的菜单信息");
	    	 return;
	    }
		if(activeMenu != ""  &&  activeMenu !=null ){
			 activeMenu = activeMenu.substring(0,activeMenu.length - 1);
		}else{
			 activeMenu = "null";
		}
	    if(noActMenu !=null && noActMenu !=""){
	    	noActMenu = noActMenu.substring(0,noActMenu.length -1);
	    }else{
	    	noActMenu = "null";
	    }
	   	var params = "activeId=" + activeMenu +"&noactiveId="+  noActMenu +"&adminNumber="+adminNumber;
	   	$.ajax({  
            url:'../../saveAuthorMenu.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) {
		     if(data.result == "success" ){
    			 alert("权限修改成功！");
    			 window.location.reload();
    		 }else{
    			 alert("权限修改失败！");
    		 }
            },
            error:function(xhr){alert(xhr.responseText);}  
        }); 
	   
	});
	
	
	//用户菜单权限管理,搜索用户菜单权限与所有的
	$("#searchAuthorMenu").click(function(){
		var adminNumber = $("#adminNumber").val();
		if(adminNumber == null || adminNumber == ""){
			alert("请输入您要搜索的账号！");
			return;
		}
		
		var params = "adminNumber="+adminNumber;
		var tr = "";
		$.ajax({  
            url:'../../menuAuthorSearch.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) { 
	    		 if(data.result =="empty"){
	    			 alert("您搜索的用户不存在！");
	    		 }else{
	    			 $.each(data,function(key,value) {
	    				  $.each(value,function(n,array) {
	    				 	  if( parseInt(array[3]) == 1){
	    				 		  if(n == 0){
	    				 			   tr += "<font  color=#FF4500>" +array[2] +"</font>: <select id= select_" + array[0]  +" onchange=chosChild('select_" + array[1] +"',this.id) >";
	    				 		  }else{
	    				 			   tr += "<br><br><font  color=#FF4500>" +array[2] +"</font>: <select id= select_" + array[0]  +" onchange=chosChild('select_" + array[1] +"',this.id) >";
	    				 		  }
	    				 		  if(array[4] == "1000"){
	    				 			  tr += "<option value=1000 selected>开通</option><option value=1111>请选择</option>" +
	    				 			  "<option value=9999>关闭</option></select><br>"
	    				 		  }else{
	    				 			  tr += "<option value=1000>开通</option><option value=1111 selected>请选择</option>" +
	    				 			  "<option value=9999><font color=#FF4500>关闭</font></option></select><br>"
	    				 		  }
	    				 		  
	    				 	  }else{
	    				 		  tr += array[2] +": <select id= select_" + array[0] + " name=select_"+ array[1] +" onchange=chosMother('select_" + array[1] +"',this.id)>";
	    				 		  if(array[4] == "1000"){
	    				 			  tr += "<option value=1000 selected>开通</option><option value=1111>请选择</option>" +
	    				 			  "<option value=9999>关闭</option></select>"
	    				 		  }else{
	    				 			  tr += "<option value=1000>开通</option><option value=1111 selected>请选择</option>" +
	    				 			  "<option value=9999>关闭</option></select>"
	    				 		  }
	    				 	  }
	    					  
	    			 	  });
	    				  $("#dataTable").html(tr);
	    			 });
	    		 }
            },
            error:function(xhr){alert(xhr.responseText);}  
        });  
	});
	
	$("#deleteAdminDepart").click(function(){
		var value="";
		$("input[type='checkbox'][ id='_ckId']").each(function(){ 
			if ($(this).attr("checked")) { 
				value += $(this).val() + ",";
			} 
		})  
		if(value == ""){
			alert("请选择删除成员信息");
			return;
		}
		var params = "array=" + value.substring(0,value.length-1);
		$.ajax({  
            url:'./departAction_deleteAdminDepart.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) {
		     if(data.result == "success" ){
    			 alert("成员删除成功！");
    			 window.location.reload();
    		 }else{
    			 alert("成员删除失败！");
    			 window.location.reload();
    		 }
            },
            error:function(xhr){alert(xhr.responseText);}  
        }); 
	});
	
	$("#saveAdminDepart").click(function(){
		var params = "";
		var stAdminNumber=$(":input[name='stAdminNumber']").val();
		var stDepartmentName=$(":input[name='stDepartmentName']").val();
		if(stAdminNumber == "" ){
			alert("请输入成员编号账号！");
			return;
		}
		if(stDepartmentName == ""){
			alert("请输入部门名称！");
			return;
		}
		
		if(stAdminNumber !="" )
		{
			params = params + "stAdminNumber=" + stAdminNumber;
		}
		if(stDepartmentName !="" )
		{
			params = params + "&stDepartmentName=" + stDepartmentName;
		}
		$.ajax({  
            url:'./departAction_saveAdminDepartInfo.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) {
		     if(data.result == "success" ){
    			 alert("成员添加成功！");
    			 window.location.reload();
    		 }else{
    			 alert("成员添加失败！" + data.result);
    			 window.location.reload();
    		 }
            },
            error:function(xhr){alert(xhr.responseText);}  
        }); 
	});
	
	
	$("#saveDepart").click(function(){
		var params = "";
		var stDepartmentName=$("#_cparam").val();
		if(stDepartmentName == ""){
			alert("请输入部门名称！");
			return;
		}
		params =  "stDepartmentName=" + stDepartmentName;
		$.ajax({  
            url:'./departAction_saveDepartInfo.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) {
		     if(data.result == "success" ){
    			 alert("部门添加成功！");
    			 window.location.reload();
    		 }else{
    			 alert("部门添加失败！" + data.result);
    			 window.location.reload();
    		 }
            },
            error:function(xhr){alert(xhr.responseText);}  
        }); 
	});
	
	$("#deleteDepart").click(function(){
		var value="";
		$("input[type='checkbox'][ id='_ckId']").each(function(){ 
			if ($(this).attr("checked")) { 
				value += $(this).val() + ",";
			} 
		})  
		if(value == ""){
			alert("请选择删除部门信息");
			return;
		}
		var params = "array=" + value.substring(0,value.length-1);
		$.ajax({  
            url:'./departAction_deleteDepartInfo.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) {
		     if(data.result == "success" ){
    			 alert("部门删除成功！");
    			 window.location.reload();
    		 }else{
    			 alert("部门删除失败！" + data.result);
    			 window.location.reload();
    		 }
            },
            error:function(xhr){alert(xhr.responseText);}  
        }); 
	});
	
	$("#modfiyDepart").click(function(){
		var value="";
		$("input[type='checkbox'][ id='_ckId']").each(function(){ 
			if ($(this).attr("checked")) { 
				value += $(this).val() + ",";
			} 
		})
		if(value.split(",").length > 2){
			alert("请选择一个部门");
			return;
		}
		if(value == ""){
			alert("请选择需该部门信息");
			return;
		}
		var stDepartmentName=$("#_cparam").val();
		if(stDepartmentName == ""){
			alert("请输入部门名称！");
			return;
		}
		var params = "array=" + value.substring(0,value.length-1) + "&stDepartmentName=" + stDepartmentName;;
		$.ajax({  
            url:'./departAction_updateDepartInfo.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) {
		     if(data.result == "success" ){
    			 alert("部门修改成功！");
    			 window.location.reload()
    		 }else{
    			 alert("部门修改失败！" + data.result);
    			 window.location.reload()
    		 }
            },
            error:function(xhr){alert(xhr.responseText);}  
        }); 
	});
	
	
	$("#stAreaPart").change(function(){
		var params =$("#stAreaPart").attr("name") +"=" +  $("#stAreaPart").attr("value") + "&array=areaType";
		$("#stAreaType").find('option').remove();
		$("#stAreaName").find('option').remove();
		$.ajax({  
            url:'./merchantAreaAction_queryAreas.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) {
			 	 $("#stAreaType").append("<option value=></option>"); 
			     $.each(data,function(key,value) {
			    	 $("#stAreaType").append("<option value="+value+">"+ value +"</option>"); 
		    	 });
            },
            error:function(xhr){alert(xhr.responseText);}  
        }); 
	});
	
	$("#stAreaType").change(function(){
		var params =$("#stAreaType").attr("name") +"=" +  $("#stAreaType").attr("value") +"&"+$("#stAreaPart").attr("name")+ "=" + $("#stAreaPart").attr("value")+"&array=areaName";
		$("#stAreaName").find('option').remove();
		$.ajax({  
            url:'./merchantAreaAction_queryAreas.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) {
			 	 $("#stAreaName").append("<option value=></option>"); 
			     $.each(data,function(key,value) {
    				 $("#stAreaName").append("<option value="+value+">"+ value +"</option>"); 
		    	 });
            },
            error:function(xhr){alert(xhr.responseText);}  
        }); 
	});
	
	$("#stAreaName").change(function(){
		var params = $("#stAreaName").attr("name")+ "=" + $("#stAreaName").attr("value") +"&"+$("#stAreaType").attr("name")+ "=" + $("#stAreaType").attr("value")
		 +"&"+$("#stAreaPart").attr("name")+ "=" + $("#stAreaPart").attr("value") + "&array=areaId";
		$.ajax({  
            url:'./merchantAreaAction_queryAreas.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) {
			     $.each(data,function(key,value) {
    					 $("#stArea").attr("value",value); 
		    	 });
            },
            error:function(xhr){alert(xhr.responseText);}  
        }); 
	});
	
	$("#merchantModify").click(function(){
		var value="";
		$("input[type='checkbox'][ id='_ckId']").each(function(){ 
			if ($(this).attr("checked")) { 
				value += $(this).val() + ",";
			} 
		})  
		if(value.split(",").length > 2){
			alert("只能选择一个商户进行修改！");
			return;
		}
		if(value == ""){
			alert("请选择一个商户进行修改！");
			return;
		}
		var params = "id=" + value.substring(0,value.length-1);
		window.location.href="./merchantAction_searchMerchantModify.action?array=" + value.substring(0,value.length-1);
	});
	
	
	$("#supplierModify").click(function(){
		var value="";
		$("input[type='checkbox'][ id='_ckId']").each(function(){ 
			if ($(this).attr("checked")) { 
				value += $(this).val() + ",";
			} 
		})  
		if(value.split(",").length > 2){
			alert("只能选择一个供应商进行修改！");
			return;
		}
		if(value == ""){
			alert("请选择一个供应商进行修改！");
			return;
		}
		var params = "id=" + value.substring(0,value.length-1);
		window.location.href="./supplierAction_searchSupplierModify.action?array=" + value.substring(0,value.length-1);
	});
	
	
	$("#saveArea").click(function(){
		var params = "";
    	$("input[type='text'][id='_cparam']").map(function() {
		   	  if(this.value != null && this.value != ""){
  				  params = params + this.name + "=" + this.value + "&";
  			  }else{
  				 alert(this.name + "不能为空！");
  			  }		  
    	});
    	params = params.substring(0,params.length-1);
		$.ajax({  
            url:'./areaAjaxAction_saveArea.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) {
		     if(data.result == "success" ){
    			 alert("城市添加成功！");
    			 alert(data.result);
    			 window.location.reload();
    		 }else{
    			 alert("城市添加失败！" + data.result);
    			 window.location.reload();
    		 }
            },
            error:function(xhr){alert(xhr.responseText);}  
        }); 
	});
	
	$("#modfiyArea").click(function(){
		var params = "";
    	$("input[type='text'][id='_cparam']").map(function() {
		   	  if(this.value != null && this.value != ""){
  				  params = params + this.name + "=" + this.value + "&";
  			  }else{
  				 alert(this.name + "不能为空！");
  			  }		  
    	});
    	
    	var value="";
		$("input[type='checkbox'][ id='_ckId']").each(function(){ 
			if ($(this).attr("checked")) { 
				value += $(this).val() + ",";
			} 
		})  
		if(value.split(",").length > 2){
			alert("只能选择一个地区进行修改！");
			return;
		}
		if(value == ""){
			alert("请选择一个地区进行修改！");
			return;
		}
    	
    	params = params + "areaBean.stAreaId=" + value.substring(0,value.length-1);
		$.ajax({  
            url:'./areaAjaxAction_modifyArea.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) {
		     if(data.result == "success" ){
    			 alert("城市修改成功！");
    			 window.location.reload();
    		 }else{
    			 alert("城市修改失败！" + data.result);
    			 window.location.reload();
    		 }
            },
            error:function(xhr){alert(xhr.responseText);}  
        }); 
	});
	
	
	$("#deleteArea").click(function(){
    	
    	var value="";
		$("input[type='checkbox'][ id='_ckId']").each(function(){ 
			if ($(this).attr("checked")) { 
				value += $(this).val() + ",";
			} 
		})  
		if(value == ""){
			alert("请选择一个地区进行删除！");
			return;
		}
    	params = "array=" + value.substring(0,value.length-1);
		$.ajax({  
            url:'./areaAjaxAction_deleteArea.action',  
            type:'post',  
            data:params,  
            dataType:'json',  
            success:function (data) {
		     if(data.result == "success" ){
    			 alert("城市删除成功！");
    			 window.location.reload();
    		 }else{
    			 alert("城市删除成功！" + data.result);
    			 window.location.reload();
    		 }
            },
            error:function(xhr){alert(xhr.responseText);}  
        }); 
	});
});  

 
